package com.youlai.system.controller;

import com.youlai.system.common.result.Result;
import com.youlai.system.model.entity.AirTicket;
import com.youlai.system.service.AirTicketService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @version 1.0
 * @Author Ricardo
 * @Date 2024/10/24 15:08
 * @注释
 */
@Tag(name = "16.机票信息接口")
@RestController
@RequestMapping("/api/v1/ticket")
@RequiredArgsConstructor
@Slf4j
public class AirTicketController {


    @Autowired
    private AirTicketService airTicketService;
    /**
     * 添加航班信息
     *
     * 该接口用于向系统中添加新的航班信息。
     * 成功时返回成功结果，失败时返回失败结果。
     *
     * @param airTicket 航班信息对象，包含航班的各项详细信息
     * @return 操作结果，成功或失败
     */
    @PostMapping("/add")
    public Result addTickets(AirTicket airTicket){
        if (airTicketService.saveOrUpdate(airTicket)){
            return Result.success();
        }else {
            return Result.failed();
        }
    }
    @PutMapping("/delete")
    public Result deleteTickets(long ticket_id){
        if (airTicketService.removeById(ticket_id)){
            return Result.success();
        }else {
            return Result.failed();
        }
    }

    @GetMapping("/select")
    public Result<List<AirTicket>> searchTickets() {
        List<AirTicket> list = airTicketService.list();
        if (list != null) {
            return Result.success(list);
        } else {
            return Result.failed();
        }
    }

    @GetMapping("/select/{id}")
    public Result<List<AirTicket>> searchTicketsById(@PathVariable("id") long id) {
        List<AirTicket> list = airTicketService.getAirTicketsById(id);
        if ( list!= null) {
            return Result.success(list);
        } else {
            return Result.failed();
        }
    }

}
